﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using MyKTV;

namespace HolidaysDemo2
{
    public partial class Form3 : Form
    {
        DBHelper dBHelper = new DBHelper();
        DataSet ds = new DataSet();
        public Form3()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Form3_Load(object sender, EventArgs e)
        {
            dBHelper.Openconnection();
            string sql = "select StationName,InputName,StartDate,EndDate,PM,Level,Notes from AirQualityInfo inner join StationInfo on AirQualityInfo.StationID = StationInfo.StationID";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, dBHelper.Connection);
            adapter.Fill(ds, "AirQualityInfo");
            this.dataGridView1.DataSource = ds.Tables["AirQualityInfo"];
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ds.Tables["AirQualityInfo"].Clear();
            if (textBox1.Text.Equals(string.Empty))
            {
                MessageBox.Show("请输入查询条件");
                return;
            }
            else
            {
                string sql = "select StationName,InputName,StartDate,EndDate,PM,Level,Notes from AirQualityInfo inner join StationInfo on AirQualityInfo.StationID = StationInfo.StationID where InputName like '%" + textBox1.Text + "%' ";
                SqlDataAdapter adapter = new SqlDataAdapter(sql, dBHelper.Connection);
                int shu = adapter.Fill(ds, "AirQualityInfo");
                this.dataGridView1.DataSource = ds.Tables["AirQualityInfo"];
                if (shu == 0)
                {
                    MessageBox.Show("未查询到信息");
                    return;
                }
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
